/*
 * @Description: 
 * @Author: fhw
 * @Date: 2023-03-27 10:20:01
 */
import { Controller, Get, Post, Body, Headers, Param, Delete, HttpCode, Query, UseGuards } from '@nestjs/common';
import { ApiResponse, ApiOperation, ApiQuery, ApiBody, ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { IdDto } from 'src/common/dto/dto';
import { CategoryService } from './category.service';
import { GetCategoryDto, CreateCategoryDto, UpdateCategoryDto } from './dto/category.dto';
import { CategoryEntity } from './entities/category.entity';
import { Roles } from 'src/common/auth/role.decorator';
@ApiBearerAuth() // swagger文档设置token
@ApiTags('游戏分类')
@Controller('category')
export class CategoryController {
  constructor(
    private readonly categoryService: CategoryService,
  ) { }

  /** 游戏分类 */
  @HttpCode(200)
  @Get('/getCategoryPage')
  @ApiResponse({
    status: 200,
    description: '游戏分类列表',
    type: [CategoryEntity],
  })
  @ApiOperation({
    tags: ['获取游戏分类'],
    summary: '获取游戏分类',
    operationId: 'getCategoryPage',
  })
  getCategoryPage(@Query() params: GetCategoryDto) {
    return this.categoryService.getCategory(params);
  }
  @HttpCode(200)
  @Post('/createCategory')
  @ApiQuery({
    description: '创建游戏分类',
    type: CreateCategoryDto,
  })
  @ApiBody({
    description: '创建游戏分类',
    type: CreateCategoryDto,
  })
  @ApiOperation({
    summary: '创建游戏分类',
    operationId: 'createCategory',
  })
  @Roles() // 自定义装璜器
  async createCategory(@Body() body: CreateCategoryDto, @Headers() headers) {
    return this.categoryService.createCategory(body, headers);
  }
  @HttpCode(200)
  @Post('/updateCategory')
  @ApiQuery({
    description: '更新游戏分类信息',
    type: UpdateCategoryDto,
  })
  @ApiBody({
    description: '更新游戏分类信息',
    type: UpdateCategoryDto,
  })
  @ApiOperation({
    summary: '更新游戏分类信息',
    operationId: 'updateCategory',
  })
  @Roles() // 自定义装璜器
  async updateCategory(@Body() body: UpdateCategoryDto, @Headers() headers) {
    return this.categoryService.updateCategory(body, headers);
  }
  @HttpCode(200)
  @Post('/deleteCategory')
  @ApiQuery({
    description: '删除游戏分类',
    type: IdDto,
  })
  @ApiBody({
    description: '删除游戏分类',
    type: IdDto,
  })
  @ApiOperation({
    summary: '删除游戏分类',
    operationId: 'deleteCategory',
  })
  @Roles() // 自定义装璜器
  async deleteCategory(@Body() body: IdDto) {
    return this.categoryService.deleteCategory(body);
  }
}
